﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace AncientEmpires_025_132
{
    public class CharacterSkill : VisibleGameEntity
    {
        

        public override void SetViewPort(int cellWidth, int cellHeigth)
        {
            ViewPort = new Vector2(0, cellHeigth - this.ListSprites[0].Textures[0].Height);
        }
        public CharacterSkill(ContentManager content, string[] strtexture, Vector2 size, Vector2 position, Vector2 toftleft)
        {
            Texture2D[] texture = new Texture2D[strtexture.Length];
            for (int i = 0; i < strtexture.Length; i ++ )
            {
                texture[i] = content.Load<Texture2D>(strtexture[i]);
            }
            ListSprites = new List<Sprite2D>();
            Sprite2D tempSprite = new Sprite2D(texture, position, toftleft);
            tempSprite.Size = size;
            ListSprites.Add(tempSprite);
            
        }


        public virtual void PlaySkill(GameTime gametime, SpriteBatch spriteBatch)
        {
        }
        public void InitTopLeft(Vector2 topleft)
        {
            for (int i = 0; i < ListSprites.Count; i++)
            {
                ListSprites[i].TopLeft = topleft;
            }
        }
        public void SetTopLeft(Vector2 topleft)
        {
            for (int i = 0; i < ListSprites.Count; i++)
            {
                ListSprites[i].TopLeft += topleft;
            }
        }

        public override void Update(GameTime gametime)
        {
            for (int i = 0; i < ListSprites.Count; i++)
            {
                ListSprites[i].Position = -ListSprites[i].TopLeft + this.ViewPort;
            }
        }
        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            for (int i = 0; i < ListSprites.Count; i++)
            {
                if (i == ISprite)
                {
                    Rectangle rect = new Rectangle();
                    if (ListSprites[i].Size.X == 0 && ListSprites[i].Size.Y == 0)
                    {
                        ListSprites[i].Size = new Vector2(ListSprites[i].Textures[ListSprites[i].ITexture].Width, ListSprites[i].Textures[ListSprites[i].ITexture].Height);
                    }
                    rect = new Rectangle((int)ListSprites[i].Position.X, (int)ListSprites[i].Position.Y, (int)ListSprites[i].Size.X, (int)ListSprites[i].Size.Y);
                    spriteBatch.Draw(ListSprites[i].Textures[ListSprites[i].ITexture], rect, Color.White);

                }
            }
        }
    }
}
